using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Banshee.Base;
using Banshee.Sources;
using Banshee.Configuration.Schema;
namespace Banshee.Winforms
{
    public partial class ImportDialog : ComponentFactory.Krypton.Toolkit.KryptonForm
    {
        public ImportDialog()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            string sources = string.Empty;
            for (int i = 0; i < source_model.Rows.Count; i++)
            {
                sources += source_model.Rows[i][0].ToString() + "|";
            }
            string sourcename = source_combo_box.SelectedValue.ToString();
            if (sourcename == "Banshee.Base.FolderImportSource")
            {
                activeSource = (IImportSource)Banshee.Base.FolderImportSource.Instance;
            }
            else if (sourcename == "Banshee.Base.FileImportSource")
            {
                activeSource = (IImportSource)Banshee.Base.FileImportSource.Instance;
            }
            

        }
        IImportSource activeSource;

        public IImportSource ActiveSource
        {
            get { return activeSource; }
            set { activeSource = value; }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
        bool doNotShowAgain;

        public bool DoNotShowAgain
        {
            get { return doNotShowAgain; }
            set { doNotShowAgain = value; }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            doNotShowAgain = checkBox1.Checked;
            ImportSchema.ShowInitialImportDialog.Set(checkBox1.Checked);
        }
        DataTable source_model = null;
        void CreateSource()
        {
            source_model = new DataTable("sources");
            DataColumn name = new DataColumn("name");
            DataColumn source = new DataColumn("source");
            source_model.Columns.Add(name);
            source_model.Columns.Add(source);
        }
        void PopulateSourceList()
        {
            CreateSource();
            
            ImportSources.Add(FolderImportSource.Instance);
            ImportSources.Add(FileImportSource.Instance);
            ImportSources.Add(HomeDirectoryImportSource.Instance);
            foreach (IImportSource source in ImportSources.Sources)
            {
                AddSource(source);
            }
            source_combo_box.DataSource = source_model;
            source_combo_box.DisplayMember = "name";
            source_combo_box.ValueMember = "source";
        }
        
        private void AddSource(IImportSource source)
        {
            source_model.Rows.Add(new object[] { source.Name, source.ToString()});
        }

        private void ImportDialog_Load(object sender, EventArgs e)
        {
            PopulateSourceList();
        }
    }
}